package poojeto.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;
import poojeto.erro.ConexaoException;

/**
 *
 * @author professor
 */
public class ConexaoImpl implements Conexao{
    private String driver;
    private String local;
    private String banco;
    private String usuario;
    private String senha;

    public ConexaoImpl(){
        ResourceBundle rb = ResourceBundle.getBundle("poojeto.util.banco");
        driver = rb.getString("driver");
        local = rb.getString("local");
        usuario = rb.getString("usuario");
        senha = rb.getString("senha");
        banco = rb.getString("banco");
    }
    
    @Override
    public Connection conectar() throws ConexaoException{
        Connection c = null;
        try {
            Class.forName(driver);
            c = DriverManager.getConnection(local+banco,usuario,senha);
        } catch (ClassNotFoundException | SQLException ex) {
            throw new ConexaoException(ex.getMessage());
        }
        return c;
    }

    @Override
    public void desconectar(Connection c) throws ConexaoException {
        try {
            c.close();
        } catch (SQLException ex) {
            throw new ConexaoException(ex.getMessage());
        }
    }
    
}
